package com.java1234.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ToolsDao {
	public int getcount(Connection c,String tno) throws SQLException
	{
		int count=0;
		String sql="select Tnumber from tools where Tno=?";
		PreparedStatement pstmt=c.prepareStatement(sql);
		pstmt.setString(1,tno);
		ResultSet rs=pstmt.executeQuery();
		while(rs.next())
		{
			count=rs.getInt("Tnumber");
		}
		return count;
	}
	public ResultSet getalltools(Connection c) throws SQLException
	{
		String sql="select * from tools";
		PreparedStatement pstmt=c.prepareStatement(sql);
		return pstmt.executeQuery();
	}
	public int update_sub(Connection c,String tno,int number) throws SQLException
	{
		String sql="update tools set Tnumber=Tnumber-? where Tno=?";
		PreparedStatement pstmt=c.prepareStatement(sql);
		pstmt.setInt(1,number);
		pstmt.setString(2,tno);
		return pstmt.executeUpdate();
	}

}
